﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 测试
{
    public class VectorHepler
    {
        /// <summary>
        /// sourceVector 向 targetVector 移动，故由 targetVector-sourceVector
        /// </summary>
        /// <param name="sourceVector">追击物向量</param>
        /// <param name="targetVector">被追击物向量</param>
        /// <returns></returns>
        public static MyVector GetNewVector(MyVector sourceVector, MyVector targetVector)
        { 
            //向量减法，方向由追击物指向被追击物
            var co_x = targetVector.X - sourceVector.X; //x分量 
            var co_y = targetVector.Y - sourceVector.Y; // y分量
            float co_length = (float)(Math.Sqrt(co_x * co_x + co_y * co_y));// 计算一下它的长度,追击物与被追击物之间向量的长度( 求模： |targetVector-sourceVector|  公式：sqrt(x*x+y*y) )
 
            co_x /= co_length;
            co_y /= co_length; 
            co_x *= sourceVector.Rete; // 这里的速率缩放比率，你可以任意调整大小 
            co_y *= sourceVector.Rete; // 可以加速：v_rate大于1；减速v_rate大于0小于1，这里就这么做！
 
            sourceVector.X += co_x;
            sourceVector.Y += co_y;
            return sourceVector; 
        }

    }
}
